package com.freewater.springboot.demo.ioc.beanpostprocessor;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * Bean初始化追踪BeanPostProcessor
 */
@Slf4j
@Setter
public class InstantiationTracingPostProcessor implements BeanPostProcessor {

    private BeanForProcessor beanForProcessor;

    @Override
    public Object postProcessBeforeInitialization(Object bean, @NotNull String beanName) throws BeansException {
        System.out.println("=====>> Bean '" + beanName + "' creating : " + bean.toString());
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, @NotNull String beanName) throws BeansException {
        System.out.println("=====>> Bean '" + beanName + "' created : " + bean.toString());
        return bean;
    }
}
